<template>
	<view class="localmore">
		<scroll-view scroll-y="true" @scrolltolower="getPetMore" class="scroll-Y">
			<view class="sub-title-text" v-if="show=='ly'">
				认领宠物有偿无偿并非本平台所设定，均为发布方所设置，本平台不做介入处理。
			</view>
			<view class="wranning" v-if="!info.auth">
				脱离平台购买宠物，不享受平台给予的半年售后保障，即：宠物半年内因病去世，平台可协助买家与卖家进行沟通补偿。
			</view>
			<view>
				<card :dataList="datalist" :isDate="false" isSale :isWrap="true" @onclickHandler="clickHandler"></card>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import card from "../../components/carditem/carditem.vue"
	export default {
		data() {
			return {
				datalist: [],
				show: null,
				info: {
					auth: true
				},
				limit: 20,
				stop: false,
			};
		},
		methods: {
			clickHandler(item, index) {
				uni.navigateTo({
					url: "/subpack/petmarketdetail/petmarketdetail?type=" + this.show + "&id=" + item._id
				})
			},
			getinfo() {
				uni.getStorage({
					key: 'userinfo',
					success: (res) => {
						this.info = res.data
						this.info.auth = Number(this.info.auth)
					},
					fail: (err) => {
						this.info.auth = true
					}
				})
			},
			async getPet(limit = 20) {
				if (this.stop) return
				let res = null
				if (this.show == "gm") {
					res = await wx.cloud.callFunction({
						name: 'logins',
						data: {
							useName: 'getPetGoods',
							limit,
						}
					})
				} else {
					res = await wx.cloud.callFunction({
						name: 'logins',
						data: {
							useName: 'searchLost',
							limit,
						}
					})
				}
				console.log("getPetGoods:", res)
				this.format(res.result.data)
				if (res.result.count < this.limit) {
					this.stop = true
				}
			},
			format(arr) {
				for (let i = 0; i < arr.length; i++) {
					let item = arr[i]
					let img = item.swiperList[0]
					this.datalist.push({
						...item,
						img
					})
				}
				// console.log('this.datalist: ', this.datalist);
			},
			getPetMore() {
				if (this.stop) {
					uni.showToast({
						mask: true,
						icon: "error",
						title: "已无更多数据~"
					})
					return
				}
				this.limit += 20
				console.log("getPetMore:-", this.limit)
				this.getPet(this.limit)
			}
		},
		onLoad(prop) {
			this.show = prop.type
			this.getinfo()
			this.getPet()
		},

		components: {
			card
		}
	}
</script>

<style lang="scss" scoped>
	.localmore {
		padding: 10upx $uni-spacing-row-base ;
		background-color: $uni-color-yellow-bg;

		// min-height: 100vh;
		// box-sizing: border-box;
		.scroll-Y {
			height: 100vh;
		}
	}
</style>